﻿<%@ Assembly Name="$SharePoint.Project.AssemblyFullName$" %>
<%@ Assembly Name="Microsoft.Web.CommandUI, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %> 
<%@ Register Tagprefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %> 
<%@ Register Tagprefix="Utilities" Namespace="Microsoft.SharePoint.Utilities" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register Tagprefix="asp" Namespace="System.Web.UI" Assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" %>
<%@ Import Namespace="Microsoft.SharePoint" %> 
<%@ Register Tagprefix="WebPartPages" Namespace="Microsoft.SharePoint.WebPartPages" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="AddAlbumUserControl.ascx.cs" Inherits="JM.JCY.SharePointComponent.PhotoAlbum.AddAlbum.AddAlbumUserControl" %>

<link href="/_layouts/JM.JCY.Resource/scripts/plUpload/jquery-ui-1.8.9.css" rel="stylesheet"
    type="text/css" />
<link href="/_layouts/JM.JCY.Resource/scripts/plUpload/jquery.ui.plupload.css" rel="stylesheet"
    type="text/css" />
<script src="/_layouts/JM.JCY.Resource/scripts/plUpload/jquery-ui.1.8.9.min.js"
    type="text/javascript"></script>
<script src="/_layouts/JM.JCY.Resource/scripts/plUpload/plupload.js" type="text/javascript"></script>
<script src="/_layouts/JM.JCY.Resource/scripts/plUpload/plupload.silverlight.js"
    type="text/javascript"></script>
<script src="/_layouts/JM.JCY.Resource/scripts/plUpload/plupload.flash.js" type="text/javascript"></script>
<script src="/_layouts/JM.JCY.Resource/scripts/plUpload/jquery.ui.plupload.js" type="text/javascript"></script>
<script type="text/javascript">
    var uploader;
    var referrerUrl = "";

    $(document).ready(function () {
        var ocpurl = $("#<%=HiddenFieldOcpUrl.ClientID %>").val();
        $("#uploader").plupload({
            runtimes: 'silverlight',
            url: '/_layouts/SharePointComponent/upload.aspx',
            max_file_size: '4mb',
            max_file_count: 20, // user can add no more then 20 files at a time
            chunk_size: '1mb',
            unique_names: true,
            multiple_queues: true,
            multipart_params: { "currentGuid": "testValue" },
            rename: true,
            sortable: true,
            filters: [
			{ title: "Image files", extensions: "jpg,jpeg,gif,tif,bmp,png" }
		],
            silverlight_xap_url: '/_layouts/JM.JCY.Resource/scripts/plUpload/plupload.silverlight.xap'
        });

        uploader = $('#uploader').plupload('getUploader');
        uploader.bind('Init', function (up, res) {
            $('a.plupload_start').css('display', 'none');
            $("#uploader_container").attr("title", "");
            $('div.plupload_header_text').text("Add files to the upload queue and click the Next button.");
        });

        uploader.bind('FilesAdded', function () {
            $("#controltoupload").text('');
        });
        LoadContorls();
        checkmsg();
        referrerUrl = document.referrer;

        $("#<%=txtAlbumDescription.ClientID %>").keypress(function (event) {
            var key = event.which;
            //all keys including return.
            if (key >= 33 || key == 13) {
                var maxLength = 256;
                var length = this.value.length;
                if (length >= maxLength) {
                    event.preventDefault();
                }
            }
        });
    });

    function startUpload() {
        // Files in queue upload them first
        if (uploader.files.length > 0) {
            for (var i = 0; i < uploader.files.length; i++) {
                if (uploader.files[i].status == 5) {
                    uploader.files[i].status = 1;
                }
            }
            // When all files are uploaded submit form
            uploader.bind('UploadProgress', function () {
                if (uploader.total.uploaded == uploader.files.length) {
                    // to do something after all file uploaded.
                    var timeId = setTimeout(function () { step1functions(); }, 1000);
                }
            });
            var currentGuid = jQuery.Guid.New();
            $("#<%=HiddenFieldGuid.ClientID %>").val(currentGuid);
            uploader.settings.multipart_params.currentGuid = currentGuid;
            uploader.start();
        } else {
            //no file selected to do something.
            $("#controltoupload").text("At least one file must be selected for uploading.");
            return false;
        }
    }

    function LoadContorls() {

        $("#<%=ImgBtnCancel.ClientID %>").click(function () {
            location.href = referrerUrl;
            return false;
        });

        var saveBtn = $("#<%=ImgBtnSave.ClientID %>");
        saveBtn.live('click', function () {
            if (Page_ClientValidate("Step1")) {

                //$("<div class=\"datagrid-mask\"></div>").css({ display: "block", width: "100%", height: $(window).height() }).appendTo("body");
                //$("<div class=\"datagrid-mask-msg\"></div>").html("Program in progress,please wait...").appendTo("body").css({ display: "block", left: ($(document.body).outerWidth(true) - 190) / 2, top: ($(window).height() - 45) / 2 });
                startUpload();
                return false;
            }

        });
    }
    function step1functions() {
        __doPostBack("CreateAlbum");
        return false;
    }

    function getSharepointObjectId() {
        return 10;
    }
</script>
<div id="divStep1">
    <table class="main" width="100%" cellpadding="0" cellspacing="0" border="0">
        <tr>
            <td valign="top" width="100%">
                <table class="content" width="99%">
                    <tr>
                        <td>
                            <div class="gallery">
                                <table width="100%" class="galleryTitle">
                                    <tr>
                                        <td width="60%">
                                            <h2 class="gallery">
                                                <img src="/_layouts/JM.JCY.Resource/images/fun_work.png">
                                                Fun@Work - Create Album</h2>
                                        </td>
                                        <td align="right" width="40%">
                                            &nbsp;
                                        </td>
                                    </tr>
                                </table>
                                <br />
                                <table class="galleryHeader" width="100%">
                                    <tr>
                                        <td width="70%">
                                            Create Album and Upload Media
                                        </td>
                                        <td width="30%" align="right">
                                            &nbsp;
                                        </td>
                                    </tr>
                                </table>
                                <table width="100%" class="galleryForm">
                                    <tr>
                                        <td width="19%">
                                           <span class="gallery">Album Name</span> <span class="mandatory">*</span>
                                        </td>
                                        <td width="1%">
                                            :
                                        </td>
                                        <td width="80%">
                                            <asp:TextBox ID="txtAlbumName" MaxLength="50" runat="server" Width="475px" onkeydown="return (event.keyCode!=13);"></asp:TextBox>
                                            <br />
                                            <asp:RequiredFieldValidator ID="rfvAlbumName" runat="server" ErrorMessage="Album Name cannot be empty."
                                                ValidationGroup="Step1" ControlToValidate="txtAlbumName" CssClass="ms-formvalidation"
                                                Display="Dynamic"></asp:RequiredFieldValidator>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td>
                                           <span class="gallery">Album Description </span> <span class="mandatory">*</span>
                                        </td>
                                        <td>
                                            :
                                        </td>
                                        <td>
                                            <asp:TextBox ID="txtAlbumDescription" runat="server" Width="475px" TextMode="MultiLine"></asp:TextBox>
                                            <br />
                                            <asp:RequiredFieldValidator ID="rfvAlbumDesc" runat="server" ErrorMessage="Album Description cannot be empty."
                                                ValidationGroup="Step1" ControlToValidate="txtAlbumDescription" CssClass="ms-formvalidation"
                                                Display="Dynamic"></asp:RequiredFieldValidator>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td>
                                           <span class="gallery">相册创建用于 </span> <span class="mandatory">*</span>
                                        </td>
                                        <td>
                                            :
                                        </td>
                                        <td>
                                            <asp:RadioButtonList ID="RadioButtonList1" runat="server">
                                                <asp:ListItem Selected="True" Value="Public">公共</asp:ListItem>
                                                <asp:ListItem Value="WorkgroupA">部门A</asp:ListItem>
                                                <asp:ListItem Value="CimmitteeA">专案小组A</asp:ListItem>
                                                <asp:ListItem Value="Personal">个人所有</asp:ListItem>
                                            </asp:RadioButtonList>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td>
                                            <span class="gallery">Select Media to Upload</span> <span class="mandatory">*</span>
                                        </td>
                                        <td>
                                            :
                                        </td>
                                        <td>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td colspan="3">
                                           <span class="gallery"> Each media uploaded has a 4MB size limit.</span>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td colspan="3">
                                            <div id="uploader">
                                                <p>
                                                    You browser doesn't have Silverlight support.</p>
                                            </div>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td colspan="3">
                                            <span class="ms-formvalidation" id="controltoupload" style="display: inline; color: red;">
                                            </span>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td colspan="3">
                                            <asp:Label ID="lblDeclareStep1" CssClass="gallery" runat="server" Text="Note: This album will be shared with Everyone. Please go to the respective workgroup / committee if you want to share the album with your workgroup / committee only."></asp:Label>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td align="right">
                                            <asp:ImageButton ID="ImgBtnSave" runat="server" ImageUrl="/_layouts/JM.JCY.Resource/images/save.png"
                                                OnClick="BtnSave_Click" />
                                            <asp:ImageButton ID="ImgBtnCancel" runat="server" ImageUrl="/_layouts/JM.JCY.Resource/images/cancel.png" />
                                        </td>
                                    </tr>
                                </table>
                            </div>
                        </td>
                    </tr>
                </table>
            </td>
        </tr>
    </table>
</div>
<div class="datagrid-mask">
</div>
<div class="datagrid-mask-msg">
</div>
<asp:HiddenField ID="HiddenFieldmsg" runat="server" />
<asp:HiddenField ID="HiddenFieldvalue" runat="server" />
<asp:HiddenField ID="HiddenFieldOcpUrl" runat="server" />
<asp:HiddenField ID="HiddenFieldGuid" runat="server" />
<asp:HiddenField ID="HiddenContextId" runat="server" />